package wan.android.photo;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ToggleButton;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/3.
 */
public class PhotoAdapter extends BaseAdapter {
    private ArrayList<PhotoGridItem> photoGridItems;
    private LayoutInflater inflater;
    private Context context;
    public PhotoAdapter(Context context,ArrayList<PhotoGridItem> photoGridItems){
        this.photoGridItems=photoGridItems;
        this.context=context;
        Log.e("test","数目:"+photoGridItems.size());
        inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return photoGridItems==null?0:photoGridItems.size();
    }

    @Override
    public Object getItem(int position) {
        return photoGridItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView=inflater.inflate(R.layout.item_gradview,null);
            viewHolder.imageView= (ImageView) convertView.findViewById(R.id.img);
            viewHolder.isSelected= (ImageView) convertView.findViewById(R.id.img_isselect);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }

        ImageLoader.getInstance().displayImage("file:///"+photoGridItems.get(position).getPath(),viewHolder.imageView);
        if(photoGridItems.get(position).isSelectedd()){
            viewHolder.isSelected.setVisibility(View.VISIBLE);
          //  if(position==getItemId(position))
            viewHolder.imageView.setAlpha(0.3f);
        }else{
            viewHolder.isSelected.setVisibility(View.GONE);
            viewHolder.imageView.setAlpha(1.0f);
        }
       return convertView;
    }
    class ViewHolder{
        ImageView imageView,isSelected;
    }
}
